package org.com.blbl.activeProvince;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class ActiveProvinceMapper extends Mapper<Object,Text, Text, IntWritable> {

    // 创建一个名为one的静态常量，其类型为IntWritable
    private final static IntWritable one = new IntWritable(1);
    private Text province = new Text();

    public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
        // 按逗号分割每行数据
        String[] fields = value.toString().split(",");

        if (fields.length > 10) {
            // 获取近一周活跃天数和总活跃天数字段，并转换为整数类型
            int recentActiveDays = Integer.parseInt(fields[6]);//周活跃天数
            int totalActiveDays = Integer.parseInt(fields[10]);//总活跃天数
            // 判断是否满足活跃用户条件（近一周活跃天数大于3且总活跃天数大于200）
            if (recentActiveDays > 3 && totalActiveDays > 200) {
                province.set(fields[4]); // 学生省份
                context.write(province, one); // 输出省份及计数1
            }
        }
    }

}

